package com.ruoyi.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.BasisAntennaTypeMapper;
import com.ruoyi.domain.BasisAntennaType;
import com.ruoyi.service.IBasisAntennaTypeService;

/**
 * 天线类型Service业务层处理
 * 
 * @author wangzebing
 * @date 2025-05-16
 */
@Service
public class BasisAntennaTypeServiceImpl implements IBasisAntennaTypeService 
{
    @Autowired
    private BasisAntennaTypeMapper basisAntennaTypeMapper;

    /**
     * 查询天线类型
     * 
     * @param antennaTypeId 天线类型主键
     * @return 天线类型
     */
    @Override
    public BasisAntennaType selectBasisAntennaTypeByAntennaTypeId(Long antennaTypeId)
    {
        return basisAntennaTypeMapper.selectBasisAntennaTypeByAntennaTypeId(antennaTypeId);
    }

    /**
     * 查询天线类型列表
     * 
     * @param basisAntennaType 天线类型
     * @return 天线类型
     */
    @Override
    public List<BasisAntennaType> selectBasisAntennaTypeList(BasisAntennaType basisAntennaType)
    {
        return basisAntennaTypeMapper.selectBasisAntennaTypeList(basisAntennaType);
    }

    /**
     * 新增天线类型
     * 
     * @param basisAntennaType 天线类型
     * @return 结果
     */
    @Override
    public int insertBasisAntennaType(BasisAntennaType basisAntennaType)
    {

        int i = basisAntennaTypeMapper.insertBasisAntennaType(basisAntennaType);

        if(i > 0 ){

            List<Map<String, Object>> bGroundEnvironmentIdAndAntennaId = basisAntennaTypeMapper.findBPositionAntennaAntennaId(basisAntennaType.getGroundEnvironmentId(), basisAntennaType.getAntennaId());
            for (Map<String, Object> map : bGroundEnvironmentIdAndAntennaId) {
                boolean b = basisAntennaTypeMapper.addbasisPositionAntennaAntennatype((Integer) map.get("id"), basisAntennaType.getAntennaTypeId());
                if(b == true){
                    return 1;
                }

            }
        }
        return i;
    }

    /**
     * 修改天线类型
     * 
     * @param basisAntennaType 天线类型
     * @return 结果
     */
    @Override
    public int updateBasisAntennaType(BasisAntennaType basisAntennaType)
    {
        return basisAntennaTypeMapper.updateBasisAntennaType(basisAntennaType);
    }

    /**
     * 批量删除天线类型
     * 
     * @param antennaTypeIds 需要删除的天线类型主键
     * @return 结果
     */
    @Override
    public int deleteBasisAntennaTypeByAntennaTypeIds(Long[] antennaTypeIds)
    {
        return basisAntennaTypeMapper.deleteBasisAntennaTypeByAntennaTypeIds(antennaTypeIds);
    }

    /**
     * 删除天线类型信息
     * 
     * @param antennaTypeId 天线类型主键
     * @return 结果
     */
    @Override
    public int deleteBasisAntennaTypeByAntennaTypeId(Long antennaTypeId)
    {
        return basisAntennaTypeMapper.deleteBasisAntennaTypeByAntennaTypeId(antennaTypeId);
    }

    @Override
    public int addBasisAntennaAntennaType(BasisAntennaType basisAntennaType) {

        List<Map<String, Object>> bGroundEnvironmentIdAndAntennaId = basisAntennaTypeMapper.findBPositionAntennaAntennaId(basisAntennaType.getGroundEnvironmentId(), basisAntennaType.getAntennaId());
        for (Map<String, Object> map : bGroundEnvironmentIdAndAntennaId) {
            boolean b = basisAntennaTypeMapper.addbasisPositionAntennaAntennatype((Integer) map.get("id"), basisAntennaType.getAntennaTypeId());
            if(b == true){
                return 1;
            }
        }
        return 0;
    }
}
